home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 March: Reference Library / Dev.CD Mar 96 RL / Dev.CD Mar 96 RL.toast / Technical Documentation / develop / develop Issue 25 / develop Issue 25 code / QD3D to QTVR / ArticleCode / Source / panoAEVT.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-20  |  4.5 KB  |  212 lines  |  [TEXT/MPCC]

  1. /*************************************************************************************************
  2.  
  3.  
  4.                         Perform Apple Events
  5.                         
  6.                         Written by Peter Falco, Apple Computer
  7.                         
  8.                         April, 1995
  9.  
  10. *************************************************************************************************/
  11.  
  12.  
  13. #include <AppleEvents.h>
  14. #include <Drag.h>
  15. #include <GestaltEqu.h>
  16. #include <Memory.h>
  17. #include <SegLoad.h>
  18.  
  19. #include "QD3DtoQTVR.h"
  20. #include "AEVT.h"
  21. #include "extern.h"
  22. #include "file.h"
  23. #include "Panorama.h"
  24. #include "document.h"
  25.  
  26.  
  27. void DoHighLevelEvent(EventRecord *ev)
  28. {
  29.     OSErr err;
  30.     
  31.     err = AEProcessAppleEvent(ev);    
  32. }
  33.  
  34.  
  35.  
  36. pascal OSErr MyAEHandleOAPP(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
  37. {
  38.     OSErr err = noErr ;
  39.     SFTypeList            theTypeList = {'3DMF'};
  40.     StandardFileReply    theReply;
  41.             
  42.     *theAppleEvent = *theAppleEvent;
  43.      *reply = *reply;
  44.      refCon = refCon;
  45.      
  46.     
  47.     StandardGetFilePreview(0L, 1, theTypeList, &theReply);
  48.  
  49.     while (theReply.sfGood)
  50.         {
  51.         MyConvert3DMFToPano(&theReply.sfFile);
  52.         StandardGetFilePreview(0L, 1, theTypeList, &theReply);
  53.         }
  54.         
  55.     SendQuitApp();
  56.  
  57.     return err;
  58. }
  59.  
  60.  
  61. //-----------------------------------------------------------------------
  62. // handler for the open document appleevent handler
  63.  
  64. pascal OSErr MyAEHandleODOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
  65. {
  66.     FSSpec         myFSS;
  67.     AEDescList    docList;
  68.     OSErr        err,
  69.                 ignoreErr;
  70.     long        index,
  71.                 itemsInList;
  72.     Size         actualSize;
  73.     AEKeyword    keywd;
  74.     DescType    returnedType;
  75.  
  76.     *theAppleEvent = *theAppleEvent;
  77.      *reply = *reply;
  78.      refCon = refCon;
  79.      
  80.     err = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&docList);
  81.     if (err == noErr) {
  82.     
  83.         // see how many descriptor items are in the list
  84.         // this is the number of documents we want to open
  85.         err = AECountItems(&docList,&itemsInList);
  86.  
  87.         // now get each descriptor record from the list
  88.         // coerce the returned data to an FSSpec record, and
  89.         // open the asoociated file
  90.         
  91.         for (index=1; index <= itemsInList && err == noErr; index++) {
  92.         
  93.             err = AEGetNthPtr(    &docList, 
  94.                                 index,
  95.                                 typeFSS,
  96.                                 &keywd,
  97.                                 &returnedType,
  98.                                 (Ptr)&myFSS,
  99.                                 sizeof(myFSS),
  100.                                 &actualSize);
  101.     
  102.             if (err == noErr) {
  103.             
  104.                 FInfo        fndrInfo ;
  105.                 
  106.                 // we now have a valid FSSpec to reference the file, we need to know 
  107.                 // what type the file is to determine which file open function to call
  108.                 // we can determine this from the finder info for the file
  109.                 
  110.                 err = FSpGetFInfo( &myFSS, &fndrInfo );    
  111.                 
  112.                 // if we got that ok, then we switch on the file  
  113.                 // type (we don't care about the creator type)    
  114.                         
  115.                 if (err == noErr)    {
  116.                 
  117.                     switch( fndrInfo.fdType ) {
  118.                         case 'TEXT':
  119.                         case '3DMF':
  120.                             MyConvert3DMFToPano(&myFSS);
  121.                             break ;
  122.                         default:
  123.                             SendQuitApp();
  124.                             break ;
  125.                     }
  126.                 }
  127.             }
  128.         }
  129.         ignoreErr = AEDisposeDesc(&docList);
  130.         SendQuitApp();
  131.     }
  132.     return err ;
  133. }
  134.  
  135. //-----------------------------------------------------------------------
  136. // handler for the print document event handler
  137.  
  138. pascal OSErr MyAEHandlePDOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
  139. {
  140.     return noErr;
  141. }
  142.  
  143.  
  144. pascal OSErr MyAEHandleQUIT(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
  145. {
  146.     OSErr             err = noErr ;        // used as return value
  147.     WindowPtr        theWindow;
  148.          
  149.     gQuitting = true;
  150.         
  151.     // attempt to close the document if window left open
  152.     theWindow = (WindowPtr)FrontWindow();
  153.     if (theWindow)
  154.         MyCloseDocument((DocumentPtr ) (((WindowPeek) theWindow)->refCon));        
  155.  
  156.     // if we closed everything up successfully, we can return noErr, otherwise
  157.     // indicate to sender of the 'quit' aevt that we canceled
  158.     
  159.     if (gQuitting) {
  160.         gQuit = true;                        // user didn't cancel
  161.         err = AEDisposeDesc(&pSelfAddress);    // Dispose of my self-addressed descriptor.
  162.     }
  163.     else {
  164.         err = userCanceledErr ;
  165.     }
  166.             
  167.     return err ;
  168. }
  169.  
  170.  
  171.  
  172. void SendQuitApp( void )
  173. {
  174.     AppleEvent    myAppleEvent, reply;
  175.     OSErr    err;
  176.     
  177.     //    Create the Apple Event.
  178.     err = AECreateAppleEvent( kCoreEventClass, 
  179.                                   kAEQuitApplication, 
  180.                                   &pSelfAddress,
  181.                                   kAutoGenerateReturnID, 
  182.                                   kAnyTransactionID, 
  183.                                   &myAppleEvent);
  184.                                   
  185.     //    Send the Apple Event.
  186.       err = AESend( &myAppleEvent, 
  187.                         &reply, 
  188.                         kAENoReply+kAENeverInteract, 
  189.                         kAENormalPriority,
  190.                         kAEDefaultTimeout, 
  191.                         nil, 
  192.                         nil);
  193.                         
  194.       AEDisposeDesc(&myAppleEvent);                // Dispose of the Apple Event.
  195. } // SendQuitApp
  196.  
  197.  
  198. void SendOpenDoc(FSSpec *myFSSpec)
  199. {
  200.  
  201.             
  202. }
  203.  
  204.  
  205.  
  206. void SendPrintDoc(FSSpec *myFSSpec)
  207. {
  208.  
  209.  
  210.  
  211.